package com.example.healthmanagement.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.healthmanagement.pojo.Foodinfo;
import com.example.healthmanagement.pojo.Sportinfo;
import com.example.healthmanagement.pojo.VO.aVo;
import com.example.healthmanagement.service.FoodinfoService;
import com.example.healthmanagement.service.SportinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chen
 * @since 2024-03-08
 */
@RestController
@RequestMapping("/sportinfo")
public class SportinfoController {
    @Autowired
    SportinfoService foodinfoService;

    @GetMapping("")
    public List<Sportinfo> getSportRecords(Sportinfo foodinfo) {
        List<Sportinfo> objectList = foodinfoService.list(new LambdaQueryWrapper<Sportinfo>().eq(foodinfo.getExerciseintensity() != null, Sportinfo::getExerciseintensity, foodinfo.getExerciseintensity())
                .eq(foodinfo.getName() != null, Sportinfo::getName, foodinfo.getName())
                .eq(foodinfo.getEnergy() != null, Sportinfo::getEnergy, foodinfo.getEnergy())
        );
        return objectList;
    }

    @PostMapping("")
    public boolean saveSportRecords(@RequestBody Sportinfo foodinfo) {

        return foodinfoService.save(foodinfo);
    }
    @PutMapping ("")
    public boolean updateSportRecords(@RequestBody Sportinfo foodinfo) {

        return foodinfoService.updateById(foodinfo);
    }
    @DeleteMapping  ("/{id}")
    public boolean DeleteSportRecords(@PathVariable("id") Long[] id) {

        return foodinfoService.removeByIds(Arrays.asList(id));
    }


}

